/************************************************************************
 * File: company.h                                                      *
 *                                                                      *
 * Copyright 2006, 2008 Colin Kern (colin.kern@gmail.com)               *
 *                                                                      *
 * This file is part of Profit.  Some previous versions were released   *
 * under the names Megacorp Mania and Acquire.                          *
 *                                                                      *
 * Profit is free software: you can redistribute it and/or modify       *
 * it under the terms of the GNU General Public License as published by *
 * the Free Software Foundation, either version 3 of the License, or    *
 * any later version.                                                   *
 *                                                                      *
 * Profit is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 * GNU General Public License for more details.                         *
 *                                                                      *
 * You should have received a copy of the GNU General Public License    *
 * along with Profit.  If not, see <http://www.gnu.org/licenses/>.      *
 ************************************************************************/
#ifndef COMPANY_H
#define COMPANY_H

#include <QWidget>
#include "globals.h"

class QString;
class QColor;
class Player;

class Company : public QWidget
{
	Q_OBJECT
	
    public:
		enum State {Normal, Lit, Dim};
		
        Company(const QString &name, const QColor &color, 
			Profit::CostGroup group, QWidget *parent = 0);
            
        const QString &getName() const;
        QChar getInitial() const;
        int getSize() const;
        Profit::CostGroup getGroup() const;
        int nShares() const;
        int getPricePerShare() const;
        int getMajorityBenefits() const;
        int getMinorityBenefits() const;
		QSize sizeHint() const;
		const QColor &getColor() const;
		bool canBuy(Player *player) const;
		bool inMerge() const;
        
        void increaseSize(int amount);
		void setSize(int size);
        void giveShares(int amount);
		void takeShares(int amount);
        void reset(int initialShares);
		void updateCurrentColor();
		void setNormalColor();
		void setLitColor();
		void setDimColor();
		void setInMerge();
		void unsetInMerge();
		
	public slots:
		void changePhase(Profit::Phase newPhase);
		void setTurn(Player *player);
		
	signals:
		void clicked(Company *company);
		void sizeChanged(int size);
		void hoverChange(bool hover, Company *company);
		
	protected:
		void paintEvent(QPaintEvent *event);
		void enterEvent(QEvent *event);
		void leaveEvent(QEvent *event);
		void mousePressEvent(QMouseEvent *event);
        
    private:
		void setMouseHover(bool hover);
		
        QString m_name;
		QColor m_color;
		QColor m_gradient1;
		QColor m_gradient2;
        int m_size;
        Profit::CostGroup m_group;
        int m_shares;
		Profit::Phase m_phase;
		Player *m_turn;
		bool m_mouseHover;
		bool m_inMerge;
		State m_state;
};

#endif
